<!--
 * @Author: 赵克强 huohuo625@163.com
 * @Date: 2023-10-23 10:41:58
 * @LastEditors: 赵克强 huohuo625@163.com
 * @LastEditTime: 2023-10-26 09:29:28
 * @FilePath: \hy-ui\src\views\app\appInfo\components\detail\dataModel\erModel\settingMainTable.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="settingMainTable">
    <el-dialog
      title="设置表"
      :visible.sync="settingTableOPen"
      width="90%"
      :before-close="close"
      border
    >
      <el-tabs v-model="activeName">
        <el-tab-pane label="当前应用" name="1"></el-tab-pane>
        <!-- <el-tab-pane label="公共应用" name="2">公共应用</el-tab-pane> -->
      </el-tabs>
      <div style="margin-bottom:20px;display:flex;justify-content: flex-end">
        <el-input
          placeholder="请输入关键字"
          v-model="queryParams.tableName"
          class="input-with-select"
        >
          <el-button
            slot="append"
            icon="el-icon-search"
            type="primary"
            style="background: #2f54eb"
            @click="getList"
          ></el-button>
        </el-input>
      </div>
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        v-if="activeName === '1'"
        v-loading="loading"
      >
        <el-table-column label=" " align="center" width="60">
          <template slot-scope="scope">
            <el-radio
              v-model="radio"
              :label="scope.$index"
              @change.native="getCurrentRow(scope.row)"
              >&nbsp;</el-radio
            >
          </template>
        </el-table-column>
        <el-table-column prop="date" label="序号" width="80" align="center">
          <template slot-scope="scope">
            {{
              (queryParams.pageNum - 1) * queryParams.pageSize +
              (scope.$index + 1)
            }}
          </template>
        </el-table-column>
        <el-table-column prop="tableName" label="表名称" align="center">
        </el-table-column>
        <el-table-column prop="remark" label="表描述" align="center">
        </el-table-column>
        <el-table-column
          prop="dataSource"
          label="数据源"
          align="center"
          :formatter="() => '本地数据源'"
        >
        </el-table-column>
        <el-table-column
          prop="entityTableStatus"
          label="实体表状态"
          align="center"
          :formatter="
            (row) =>
              row.entityTableStatus
                ? selectDictLabel(
                    dict.type.pt_app_entity_status,
                    row.entityTableStatus
                  )
                : '--'
          "
        >
        </el-table-column>
      </el-table>
      <div class="pagination">
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="handleSubmit" :loading="btnLoading">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getOnlineList } from "@/api/app/dataModel/entityModel";
export default {
  name: "settingMainTable",
  dicts: ["pt_app_entity_status"],
  props: {
    settingTableOPen: {
      type: Boolean,
      default: false,
    },
    settingTableClose: {
      type: Function,
      default: () => {},
    },
    appId: {
      type: String,
      default: "",
    },
    close:{
      type: Function,
      default: () => {},
    },
    btnLoading: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      radio: "",
      activeName: "1",
      chooseData: {},
      tableData: [],
      queryParams: { tableName: undefined, pageNum: 1, pageSize: 10 },
      loading: false,
      total: 0,
      propsRow: {},
    };
  },

  mounted() {
    this.getList();
  },

  methods: {
    async getList() {
      this.loading = true;
      const res = await getOnlineList({
        ...this.queryParams,
        appId: this.appId,
      });
      if (res.code == 200) {
        this.tableData = res.rows;
        this.total = res.total;
      }
      this.loading = false;
    },
    handleSubmit() {
      if (!Object.keys(this.chooseData).length)
        return this.$message.error("请选择表数据");
      this.settingTableClose(this.activeName, this.chooseData);
    },
    getCurrentRow(key) {
      this.chooseData = key;
    },
  },
};
</script>

<style lang="scss" scoped>
.settingMainTable {
  ::v-deep .el-radio__label {
    display: none;
  }
    ::v-deep .input-with-select {
      width: 300px;

    }
     ::v-deep .el-icon-search {
      color: #fff;
    }
}
</style>
